home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ahoy 1986 August
/
Ahoy_Magazine_86-08_1986_Double_L.d64
/
The Integrator
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-10-26
|
2KB
|
73 lines
10 print"[147]":poke53280,6:poke53281,1:poke646,0
20 rem the integrator
30 rem rupert report #32
40 rem
50 false=0 : true=not false
60 c128=false :if ds$<>"" then c128=true
70 n=5 :rem initial number of intervals
80 gosub 190 :rem define function and specify limits
90 rem = = = = = main loop = = = = =
100 if c128 then gosub 260 :rem plot function - (c128 only)
110 gosub 350 :rem integrate function
120 gosub 480 :rem show results
130 gosub 530 :rem get # of intervals
140 if not fini then 100
150 rem - change next line for desired default graphics mode -
160 if c128 then (NULL) 5
170 end
180 rem = = = = = = = = = = = = = = = =
190 rem = define function & limits =
200 def fna(x) = sqr(r*r-x*x)
210 r=150 : rem circle of radius 150
220 x0=0 : x1=r :rem integration limits
230 ss=1 :rem graph step size
240 dx=(x1-x0)/n :rem interval size
250 return
260 rem = set up & draw function =
270 (NULL) 2,1,22
280 (NULL) 1,10,0 to 10,170 to 320,170 : rem draw axes
290 for x=x0 to x1 step ss
300 y=fna(x)
310 xp=10+x : yp=170-y
320 (NULL) 1,xp,yp
330 next
340 return
350 rem = integrate function =
360 s0=sum : sum=0
370 for kk=.5 to n
380 x=x0+dx*kk
390 y=fna(x)
400 area=y*dx
410 sum=sum+area
420 if not c128 then 460
430 xu=12+x-dx/2 : yu=170-y
440 xl=10+x+dx/2 : yl=170
450 (NULL) 1,xu,yu,xl,yl,0,1
460 next
470 return
480 rem = show results =
490 if n0=0 or not c128 then 510
500 print"intervals :" n0 " area :" s0
510 print"intervals :" n " area :" sum
520 return
530 rem = update number of intervals =
540 n0=n
550 input"how many intervals (0 to stop)";n
560 if n<1 then fini=true : goto 580
570 dx=(x1-x0)/n
580 return
590 rem =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
600 rem high-res c128 graphics screen dump to epson mx-80 printer
610 rem (when program is done, type run 1000)
1000 e$=chr$(27) : n1=200 : n2=0
1010 open222,4 : print#222,e$"a"chr$(8)
1020 for col=0 to 39
1030 for row=24 to 0 step -1
1040 m=8192+8*col+320*row
1050 for lne=7 to 0 step -1
1060 a$=a$+chr$(peek(m+lne))
1070 next lne : next row
1080 print#222,e$"k"chr$(n1)chr$(n2)a$
1090 a$="" : next col
1100 print#222 : close222 :end